#include "../../../common/data_es.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式, false-调试; true-发布;");
DEFINE_string(log_file, "", "发布模式下, 用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下, 用于指定日志输出等级");  //trace default 0

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器url");
int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    
    xchat::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto es_client = xchat::ESClientFactory::createClient({FLAGS_es_host});

    auto es_user = std::make_shared<xchat::ESUser>(es_client);

    //es_user->createIndex();
    //es_user->appendData("用户ID1", "手机号1", "用户名1", "用户描述1", "用户头像1");
    //es_user->appendData("用户ID2", "手机号2", "用户名2", "用户描述2", "用户头像2");
    //es_user->appendData("用户ID3", "手机号3", "用户名3", "用户描述3", "用户头像3");
    es_user->appendData("f7aa-b126b9c7-0001", "", "张三", "", "");

    auto res = es_user->search("用户", {"用户ID1"});

    for(auto &u : res)
    {
        std::cout << "----------------" << std::endl;
        std::cout << "用户ID: " << u.user_id() << std::endl;
        std::cout << "手机号: " << *u.phone() << std::endl;
        std::cout << "用户名: " << *u.nickname() << std::endl;
        std::cout << "用户描述: " << *u.description() << std::endl;
        std::cout << "用户头像: " << *u.avatar_id() << std::endl;
    }


    return 0;
}